package cc.rengu.igas.bsps.core.realize.impl;

import cc.rengu.igas.bsps.common.constant.BspsAppParamConstant;
import cc.rengu.igas.bsps.common.constant.BspsTreeNodeConstant;
import cc.rengu.igas.bsps.common.constant.DubboMethodConstant;
import cc.rengu.igas.bsps.common.enums.RespCodeEnum;
import cc.rengu.igas.bsps.core.realize.BspsComboDealService;
import cc.rengu.igas.bsps.facade.base.Header;
import cc.rengu.igas.momp.facade.bean.PaymentOrderDetailBean;
import cc.rengu.igas.momp.facade.request.ComboPaymentRequest;
import cc.rengu.igas.momp.facade.request.ComboPaymentReversalRequest;
import cc.rengu.igas.momp.facade.response.ComboPaymentResponse;
import cc.rengu.igas.momp.facade.result.Result;
import cc.rengu.oltp.service.common.constant.AppParamConstant;
import cc.rengu.oltp.service.common.constant.TreeNodeConstant;
import cc.rengu.oltp.service.common.dao.PayOrderInfoMapper;
import cc.rengu.oltp.service.common.dao.UserOrderInfoMapper;
import cc.rengu.oltp.service.common.dao.impl.PayOrderInfoMapperImpl;
import cc.rengu.oltp.service.common.dao.impl.UserOrderInfoMapperImpl;
import cc.rengu.oltp.service.common.entity.MchntOrderInfo;
import cc.rengu.oltp.service.common.entity.PayOrderInfo;
import cc.rengu.oltp.service.common.entity.UserOrderInfo;
import cc.rengu.oltp.service.common.enums.*;
import cc.rengu.oltp.service.model.BizException;
import cc.rengu.oltp.service.realize.DubboService;
import cc.rengu.oltp.service.realize.OrderService;
import cc.rengu.oltp.service.realize.impl.DubboServiceImpl;
import cc.rengu.oltp.service.realize.impl.OrderServiceImpl;
import cc.rengu.oltp.utility.util.AmountUtil;
import cc.rengu.oltp.utility.util.BeanUtil;
import cc.rengu.oltp.utility.util.DateUtil;
import cc.rengu.oltp.utility.util.XmlTreeUtil;
import cc.rengu.utility.log.RgLog;
import cc.rengu.utility.log.RgLogger;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/*
 * Create by fuyp on 2020-5-15
 * Copy By MCPS
 */
public class BspsComboDealServiceImpl implements BspsComboDealService {
    private RgLogger rglog = RgLog.getLogger(this.getClass().getName());

    @Override
    public void comboPayment(UserOrderInfo userOrderInfo, MchntOrderInfo mchntOrderInfo, Header header) throws Exception {
        /*修改header里的源系统标识*/
        header.setSrcSysId(AppParamConstant.SYS_ID);
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String txnNum = mchntOrderInfo.getTxnNum();

        String comboBizProdCode = getComboBizProdCode(txnNum, mchntOrderInfo.getBizType());
        if (null == comboBizProdCode) {
            rglog.error("未配置营销产品编码");
            throw new BizException(RespCodeEnum.NOT_SUPPORT_ORT_TYPE.getRespCode(), RespCodeEnum.NOT_SUPPORT_ORT_TYPE.getRespDesc());
        }
        rglog.debug("打印营销产品编码<{}>", comboBizProdCode);
        /*本行营销*/
        //手机银行生成二维码后,会在新平台的用户订单插入一条数据,[orderUrl]即二维码号
        //收单侧在扫银联二维码收款时,去用户订单查询,获取付款账号,上送营销
        String payQrCode = xmlTreeUtil.getXmlTreeStringValue("payQrCode");
        //营销用户编号,如果银联码且本行卡,送付款账号。如果不是,送码号
        String mompUserId = payQrCode;
        if (payQrCode.startsWith("62")) {
            UserOrderInfoMapper userOrderInfoMapper = new UserOrderInfoMapperImpl();
            UserOrderInfo qrCodeUserOrderInfo = userOrderInfoMapper.selectUserOrderInfoByOrderUrl(userOrderInfo.getInstId(), payQrCode);
            if (null != qrCodeUserOrderInfo) {
                rglog.debug("用户订单信息<{}>", JSONObject.toJSONString(qrCodeUserOrderInfo));
                JSONObject jsonObject = JSONObject.parseObject(qrCodeUserOrderInfo.getRemark3());
                mompUserId = jsonObject.getString("acctNo");
            }
        }

        /*定义订单操作接口*/
        OrderService orderService = new OrderServiceImpl();
        /*定义营销支付订单对象*/
        PayOrderInfo comboPayOrderInfo = new PayOrderInfo();
        BeanUtil.beanCopy(userOrderInfo, comboPayOrderInfo);
        comboPayOrderInfo.setTxnNum(userOrderInfo.getTxnNum());
        comboPayOrderInfo.setSysSeqNum(userOrderInfo.getSysSeqNum());
        comboPayOrderInfo.setMsgDstId(ChannelEnum.MOMP.getChannelType());
        comboPayOrderInfo.setMchntNo(mchntOrderInfo.getMchntNo());

        comboPayOrderInfo.setDstCallIndex("0");
        /*系统流水号：对账主键sys_seq_num+序号*/
        comboPayOrderInfo.setChannelReconKey(userOrderInfo.getSysSeqNum() + comboPayOrderInfo.getDstCallIndex());
        comboPayOrderInfo.setChannelSeqNum(comboPayOrderInfo.getChannelReconKey());
        /*获取通道交易码*/
        comboPayOrderInfo.setDstTxnNum("P01MO003");
        /*设置支付方式*/
        comboPayOrderInfo.setPayType("*");
        /*实际支付金额*/
        comboPayOrderInfo.setRealPayAmt(comboPayOrderInfo.getOrderAmt());
        /*设置支付订单状态,交易状态，0：初始状态，业务状态：00处理中*/
        comboPayOrderInfo.setTransStatus(TransStatusEnum.TRANS_INIT.getStatus());
        comboPayOrderInfo.setBizStatus(BizStatusEnum.FINISH.getStatus());

        rglog.info("打印营销支付订单表<{}>", JSON.toJSONString(comboPayOrderInfo));
        /*记录营销支付订单*/
        if (!orderService.registerOrderInfo(null, null, comboPayOrderInfo)) {
            rglog.error("登记支付订单信息失败,instId:<{}>,sysSeqNum:<{}>,mchntOrderId:<{}>,msgDstId:<{}>",
                    comboPayOrderInfo.getInstId(), comboPayOrderInfo.getSysSeqNum(), comboPayOrderInfo.getMchntOrderId(), comboPayOrderInfo.getMsgDstId());
            /*更新用户商户订单状态*/
            userOrderInfo.setBizStatus(BizStatusEnum.FAILED.getStatus());
            userOrderInfo.setOrderStatus(OrderStatusEnum.CLOSE.getStatus());
            userOrderInfo.setTransStatus(TransStatusEnum.SYSTEM_REJECT.getStatus());
            mchntOrderInfo.setBizStatus(BizStatusEnum.FAILED.getStatus());
            mchntOrderInfo.setTransStatus(TransStatusEnum.SYSTEM_REJECT.getStatus());
            orderService.updateOrderInfo(userOrderInfo, Arrays.asList(mchntOrderInfo), null);
            throw new BizException(RespCodeEnum.INSERT_TXN_EXPAND_ERROR.getRespCode(), RespCodeEnum.INSERT_TXN_EXPAND_ERROR.getRespDesc());
        }
        /*设置请求报文*/
        ComboPaymentRequest comboPaymentRequest = new ComboPaymentRequest();
        /*报文头赋值*/
        cc.rengu.igas.momp.facade.base.Header comboHeader = new cc.rengu.igas.momp.facade.base.Header();
        BeanUtil.beanCopy(header, comboHeader);
        comboHeader.setTraceNo(comboPayOrderInfo.getChannelReconKey());
        comboHeader.setTxnNum("P01MO003");
        /*修改header里的源系统标识*/
        comboHeader.setSrcSysId(AppParamConstant.SYS_ID);
        comboPaymentRequest.setHeader(comboHeader);
        /*业务产品代码,组合营销产品代码*/
        comboPaymentRequest.setBizProdCode(comboBizProdCode);
        /*商户订单号*/
        comboPaymentRequest.setMchntOrderId(userOrderInfo.getMchntOrderId());
        /*订单金额*/
        comboPaymentRequest.setTransAmt(userOrderInfo.getOrderAmt());
        /*获取 设置用户编号*/
        comboPaymentRequest.setUserId(mompUserId);
        /*设置请求订单信息*/
        PaymentOrderDetailBean paymentOrderDetailBean = new PaymentOrderDetailBean();
        /*商户号*/
        paymentOrderDetailBean.setMchntNo(mchntOrderInfo.getMchntNo());
        /*订单金额*/
        paymentOrderDetailBean.setOrderAmt(mchntOrderInfo.getOrderAmt());
        /*手续收取模式*/
        paymentOrderDetailBean.setFeeInputMode(mchntOrderInfo.getFeeInputMode());
        /*应收手续金额*/
        paymentOrderDetailBean.setMchntFeeReceivable(mchntOrderInfo.getMchntFee());
        /*手续费比率*/
        paymentOrderDetailBean.setMchntFeeReceivableRate(mchntOrderInfo.getFeeRate());
        /*商户清算金额*/
        paymentOrderDetailBean.setMchntSettleAmt(mchntOrderInfo.getOrderAmt());
        /*费率类型*/
        String feeType = xmlTreeUtil.getXmlTreeStringValue("feeType");
        paymentOrderDetailBean.setFeeType(feeType);
        /*业务产品代码*/
        paymentOrderDetailBean.setBizProdCode(mchntOrderInfo.getBizProdCode());
        List<PaymentOrderDetailBean> paymentOrderDetailBeanList = new ArrayList<>();
        paymentOrderDetailBeanList.add(paymentOrderDetailBean);
        comboPaymentRequest.setOrderDetailList(paymentOrderDetailBeanList);
        rglog.debug("打印营销请求报文<{}>", JSON.toJSONString(comboPaymentRequest));
        DubboService dubboService = new DubboServiceImpl();

        Result<ComboPaymentResponse> comboPaymentResponseResult = (Result) dubboService.callDubboService("paymentService", "comboPayment", comboPaymentRequest);
        if (null == comboPaymentResponseResult || !comboPaymentResponseResult.isSuccess() || null == comboPaymentResponseResult.getResult()) {
            /*营销失败，更新营销支付订单表状态失败*/
            rglog.error("调用营销失败，返回结果报文NULL");
            comboPayOrderInfo.setTransStatus(TransStatusEnum.SYSTEM_REJECT.getStatus());
            comboPayOrderInfo.setBizStatus(BizStatusEnum.FAILED.getStatus());
            if (null == comboPaymentResponseResult || null == comboPaymentResponseResult.getResult()) {
                comboPayOrderInfo.setRespCode(RespCodeEnum.CALL_BIZ_SERVICE_ERROR.getRespCode());
                comboPayOrderInfo.setRespDesc(RespCodeEnum.CALL_BIZ_SERVICE_ERROR.getRespDesc());
            } else {
                comboPayOrderInfo.setRespCode(comboPaymentResponseResult.getResult().getRespCode());
                comboPayOrderInfo.setRespDesc(comboPaymentResponseResult.getResult().getRespDesc());
            }
            orderService.updateOrderInfo(null, null, comboPayOrderInfo);
        } else if (DubboMethodConstant.DUBBO_OVERTIME.equals(comboPaymentResponseResult.getResult().getRespCode()) || OltpRpcdEnum.BIZ_PROCESS_TIMEOUT.getRespCode().equals(comboPaymentResponseResult.getResult().getRespCode())) {
            /*响应超时，更新营销支付订单表并营销撤销*/
            rglog.error("调用营销超时{}", comboPaymentResponseResult.getResult().getRespDesc());
            /*用于营销冲正处理*/
            xmlTreeUtil.setXmlTreeObjectValue(BspsTreeNodeConstant.MOMP_COMPAY_ORDER_INFO, comboPayOrderInfo);
            /*营销冲正*/
            cancelComboPayment(userOrderInfo.getSysSeqNum(), header);
            comboPayOrderInfo.setTransStatus("3");
            comboPayOrderInfo.setRespCode(comboPaymentResponseResult.getResult().getRespCode());
            comboPayOrderInfo.setRespDesc(comboPaymentResponseResult.getResult().getRespDesc());
            orderService.updateOrderInfo(null, null, comboPayOrderInfo);
        } else if (OltpRpcdEnum.TRANS_SUCCESS.getRespCode().equals(comboPaymentResponseResult.getResult().getRespCode())) {
            rglog.debug("打印营销相应报文<{}>", JSON.toJSONString(comboPaymentResponseResult.getResult()));
            ComboPaymentResponse comboPaymentResponse = comboPaymentResponseResult.getResult();
            PaymentOrderDetailBean mompOrderDetail = comboPaymentResponse.getOrderDetailList().get(0);

            /*用户优惠营销金额*/
            String userDiscountAmt = comboPaymentResponse.getTotalSubsidy();
            /*对客营销金额,商户开展免充值营销活动时商户对客营销金额*/
            String customerMarketAmt = "0.00";

            /*商户清算本金:订单金额-对客营销金额*/
            String realSettleAmt = comboPayOrderInfo.getRealPayAmt();
            /*营销通道优惠金额,只记录预充值的,即用户优惠营销金额-免充值部分*/
            String mompChannelDiscountAmt = userDiscountAmt;
            /*商户手续费优惠*/
            String mchntFeeDiscountAmt = mompOrderDetail.getMchntFeeDiscount();
            /*实收手续费(这个值是不变的,手续费优惠是上送的应收手续费-实收手续费得来)*/
            String mchntFeeActual = mompOrderDetail.getMchntFeeActual();

            //0-轧差清算（免充值）;1-正常清算（预充值）
            if ("0".equals(mompOrderDetail.getMoneyOffSettlementMethod())) {
                /*减去免充值的部分*/
                realSettleAmt = AmountUtil.subtraction(realSettleAmt, mompOrderDetail.getMoneyOffSubsidyMchnt());
                mompChannelDiscountAmt = AmountUtil.subtraction(mompChannelDiscountAmt, mompOrderDetail.getMoneyOffSubsidyTotal());
                customerMarketAmt = AmountUtil.addition(customerMarketAmt, mompOrderDetail.getMoneyOffSubsidyMchnt());
            }
            if ("0".equals(mompOrderDetail.getCouponMchntSettleMethod())) {
                /*减去免充值的部分*/
                realSettleAmt = AmountUtil.subtraction(realSettleAmt, mompOrderDetail.getCouponMchntSubsidy());
                mompChannelDiscountAmt = AmountUtil.subtraction(mompChannelDiscountAmt, mompOrderDetail.getCouponTotalSubsidy());
                customerMarketAmt = AmountUtil.addition(customerMarketAmt, mompOrderDetail.getCouponMchntSubsidy());
            }

            userOrderInfo.setRealPayAmt(AmountUtil.subtraction(userOrderInfo.getRealPayAmt(), userDiscountAmt));//真正支付:待支付-通道侧优惠,此时未调通道,登记待支付
            userOrderInfo.setRealDiscountAmt(AmountUtil.addition(userOrderInfo.getRealDiscountAmt(), userDiscountAmt));//用户优惠：营销模块对客+通道优惠

            mchntOrderInfo.setCustomerMarketAmt(customerMarketAmt);//对客营销,商户开展免充值营销活动时商户对客营销金额
            mchntOrderInfo.setRedeemCouponIds(mompOrderDetail.getCouponNo());//卡券编号
            mchntOrderInfo.setRealSettleAmt(realSettleAmt);//实际清算本金

            /*合并支付,已算应收、实收、优惠手续费*/
            mchntOrderInfo.setMchntFee(mompOrderDetail.getMchntFeeReceivable());
            mchntOrderInfo.setRealMchntFee(mchntFeeActual);
            mchntOrderInfo.setMchntDiscountFee(mchntFeeDiscountAmt);
            // /*有免充值对客营销 并且 没有手续费优惠,重新计算手续费*/
            // if (0 != AmountUtil.compare("0", customerMarketAmt) && 0 == AmountUtil.compare("0", mchntFeeDiscountAmt)) {
            //     //有免充值的对客营销,并且没有手续费优惠,那么重新计算手续费后,肯定比原计算得手续费少
            //     rglog.debug("存在商户免充值的对客营销金额,并且没有手续费优惠,重新计算商户手续费.");
            //     MchntService mchntService = new MchntServiceImpl();
            //     if (mchntService.calcMchntFee(mchntOrderInfo, null)) {
            //         mchntOrderInfo.setRealMchntFee(mchntOrderInfo.getMchntFee());
            //         mchntOrderInfo.setMchntDiscountFee("0.00");
            //         // /*计算出商户应收手续费*/
            //         // if (-1 == AmountUtil.compare(mchntOrderInfo.getMchntFee(), mchntFeeActual)) {
            //         //     //计算得手续费应收比原实收少,按照新计算的手续费收取
            //         //     mchntOrderInfo.setRealMchntFee(mchntOrderInfo.getMchntFee());
            //         //     mchntOrderInfo.setMchntDiscountFee("0.00");
            //         // } else {
            //         //     //计算得手续费大于等于原应收,实收还是按照营销计算金额,重新计算手续费优惠
            //         //     mchntOrderInfo.setRealMchntFee(mchntFeeActual);
            //         //     mchntOrderInfo.setMchntDiscountFee(AmountUtil.subtraction(mchntOrderInfo.getMchntFee(), mchntOrderInfo.getRealMchntFee()));
            //         // }
            //     } else {
            //         //计算手续费失败
            //         mchntOrderInfo.setRealMchntFee(mchntFeeActual);
            //         mchntOrderInfo.setMchntDiscountFee(AmountUtil.subtraction(mchntOrderInfo.getMchntFee(), mchntOrderInfo.getRealMchntFee()));
            //     }
            //     mchntOrderInfo.setRealSettleFlag(AppParamConstant.NO);
            // } else {
            //     mchntOrderInfo.setRealMchntFee(mchntFeeActual);
            //     mchntOrderInfo.setMchntDiscountFee(mchntFeeDiscountAmt);//设置优惠手续费
            // }

            /*手续费计算,营销手续费优惠计算,均已保留两位小数*/
            // //D0实时清算商户手续费四舍五入保留两位小数
            // if (AppParamConstant.YES.equals(mchntOrderInfo.getRealSettleFlag())) {
            //     mchntOrderInfo.setRealMchntFee(AmountUtil.rounding(mchntOrderInfo.getRealMchntFee(), 2));
            // }

            /*设置商户商户结算净额:清算本金-实收手续费*/
            mchntOrderInfo.setMchntSettleAmt(AmountUtil.subtraction(mchntOrderInfo.getRealSettleAmt(), mchntOrderInfo.getRealMchntFee()));

            comboPayOrderInfo.setChannelDiscountAmt(mompChannelDiscountAmt);//营销通道优惠金额

            userOrderInfo.setUpdateTime(DateUtil.getCurrentDateTime(BspsAppParamConstant.yyyy_MM_dd_HHmmssSSS));
            mchntOrderInfo.setUpdateTime(DateUtil.getCurrentDateTime(BspsAppParamConstant.yyyy_MM_dd_HHmmssSSS));
            comboPayOrderInfo.setUpdateTime(DateUtil.getCurrentDateTime(BspsAppParamConstant.yyyy_MM_dd_HHmmssSSS));
            /*营销订单状态设置*/
            comboPayOrderInfo.setTransStatus(TransStatusEnum.TRANS_SUCC.getStatus());
            comboPayOrderInfo.setBizStatus(BizStatusEnum.FINISH.getStatus());
            comboPayOrderInfo.setRespCode(comboPaymentResponseResult.getResult().getRespCode());
            comboPayOrderInfo.setRespDesc(comboPaymentResponseResult.getResult().getRespDesc());
            /*打印用户订单和商户订单*/
            rglog.debug(JSON.toJSONString(userOrderInfo));
            rglog.debug(JSON.toJSONString(mchntOrderInfo));
            /*更新内部树用户订单表信息和商户订单表信息*/
            xmlTreeUtil.setXmlTreeObjectValue(BspsTreeNodeConstant.USER_ORDER_INFO, userOrderInfo);
            xmlTreeUtil.setXmlTreeObjectValue(BspsTreeNodeConstant.MCHNT_ORDER_INFO, mchntOrderInfo);
            List<MchntOrderInfo> mchntOrderInfoList = new ArrayList<>();
            mchntOrderInfoList.add(mchntOrderInfo);
            if (!orderService.updateOrderInfo(userOrderInfo, mchntOrderInfoList, comboPayOrderInfo)) {
                rglog.error("更新用户、商户订单信息失败,instId:<{}>,sysSeqNum:<{}>,mchntOrderId:<{}>",
                        userOrderInfo.getInstId(), userOrderInfo.getSysSeqNum(), userOrderInfo.getMchntOrderId());
                throw new BizException(RespCodeEnum.UPDATE_ORDER_STATUS_ERROR.getRespCode(), RespCodeEnum.UPDATE_ORDER_STATUS_ERROR.getRespDesc());
            }
            /*用于营销冲正处理*/
            xmlTreeUtil.setXmlTreeObjectValue(BspsTreeNodeConstant.MOMP_COMPAY_ORDER_INFO, comboPayOrderInfo);
        } else {
            /*营销失败，更新营销支付订单表状态失败*/
            rglog.error("调用营销失败{}", comboPaymentResponseResult.getResult().getRespDesc());
            comboPayOrderInfo.setTransStatus(TransStatusEnum.SYSTEM_REJECT.getStatus());
            comboPayOrderInfo.setBizStatus(BizStatusEnum.FAILED.getStatus());
            comboPayOrderInfo.setRespCode(comboPaymentResponseResult.getResult().getRespCode());
            comboPayOrderInfo.setRespDesc(comboPaymentResponseResult.getResult().getRespDesc());
            orderService.updateOrderInfo(null, null, comboPayOrderInfo);
        }
    }

    @Override
    public void forClientPayment(UserOrderInfo userOrderInfo, MchntOrderInfo mchntOrderInfo, Header header) throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        /*修改header里的源系统标识*/
        header.setSrcSysId(AppParamConstant.SYS_ID);
        String txnNum = mchntOrderInfo.getTxnNum();

        String comboBizProdCode = getComboBizProdCode(txnNum, mchntOrderInfo.getBizType());
        if (null == comboBizProdCode) {
            rglog.error("未配置营销产品编码");
            throw new BizException(RespCodeEnum.NOT_SUPPORT_ORT_TYPE.getRespCode(), RespCodeEnum.NOT_SUPPORT_ORT_TYPE.getRespDesc());
        }
        rglog.debug("打印营销产品编码<{}>", comboBizProdCode);
        /*本行营销*/
        //手机银行生成二维码后,会在新平台的用户订单插入一条数据,[orderUrl]即二维码号
        //收单侧在扫银联二维码收款时,去用户订单查询,获取付款账号,上送营销
        String payQrCode = xmlTreeUtil.getXmlTreeStringValue("payQrCode");
        //营销用户编号,如果银联码且本行卡,送付款账号。如果不是,送码号
        String mompUserId = payQrCode;
        if (payQrCode.startsWith("62")) {
            UserOrderInfoMapper userOrderInfoMapper = new UserOrderInfoMapperImpl();
            UserOrderInfo qrCodeUserOrderInfo = userOrderInfoMapper.selectUserOrderInfoByOrderUrl(userOrderInfo.getInstId(), payQrCode);
            if (null != qrCodeUserOrderInfo) {
                rglog.debug("用户订单信息<{}>", JSONObject.toJSONString(qrCodeUserOrderInfo));
                JSONObject jsonObject = JSONObject.parseObject(qrCodeUserOrderInfo.getRemark3());
                mompUserId = jsonObject.getString("acctNo");
            }
        }
        /*定义订单操作接口*/
        OrderService orderService = new OrderServiceImpl();
        /*定义营销支付订单对象*/
        PayOrderInfo mompForClientPayOrderInfo = new PayOrderInfo();
        BeanUtil.beanCopy(userOrderInfo, mompForClientPayOrderInfo);
        mompForClientPayOrderInfo.setTxnNum(userOrderInfo.getTxnNum());
        mompForClientPayOrderInfo.setMchntNo(mchntOrderInfo.getMchntNo());
        mompForClientPayOrderInfo.setMsgDstId(ChannelEnum.MOMP.getChannelType());
        mompForClientPayOrderInfo.setDstCallIndex("0");
        /*系统流水号：对账主键sys_seq_num+序号*/
        mompForClientPayOrderInfo.setChannelReconKey(userOrderInfo.getSysSeqNum() + mompForClientPayOrderInfo.getDstCallIndex());
        mompForClientPayOrderInfo.setChannelSeqNum(mompForClientPayOrderInfo.getChannelReconKey());
        /*获取通道交易码*/
        mompForClientPayOrderInfo.setDstTxnNum("P01MO003");
        /*设置支付方式*/
        mompForClientPayOrderInfo.setPayType("*");
        /*订单金额:初始订单金额*/
        mompForClientPayOrderInfo.setOrderAmt(mchntOrderInfo.getOrderAmt());
        /*实际支付金额:上送通道的金额*/
        mompForClientPayOrderInfo.setRealPayAmt(mchntOrderInfo.getRealSettleAmt());
        /*设置支付订单状态,交易状态，0：初始状态，业务状态：00处理中*/
        mompForClientPayOrderInfo.setTransStatus(TransStatusEnum.TRANS_INIT.getStatus());
        mompForClientPayOrderInfo.setBizStatus(BizStatusEnum.FINISH.getStatus());

        rglog.info("打印营销支付订单表<{}>", JSON.toJSONString(mompForClientPayOrderInfo));
        /*记录营销支付订单*/
        if (!orderService.registerOrderInfo(null, null, mompForClientPayOrderInfo)) {
            rglog.error("登记支付订单信息失败,instId:<{}>,sysSeqNum:<{}>,mchntOrderId:<{}>,msgDstId:<{}>",
                    mompForClientPayOrderInfo.getInstId(), mompForClientPayOrderInfo.getSysSeqNum(), mompForClientPayOrderInfo.getMchntOrderId(), mompForClientPayOrderInfo.getMsgDstId());
            /*更新用户商户订单状态*/
            userOrderInfo.setBizStatus(BizStatusEnum.FAILED.getStatus());
            userOrderInfo.setOrderStatus(OrderStatusEnum.CLOSE.getStatus());
            userOrderInfo.setTransStatus(TransStatusEnum.SYSTEM_REJECT.getStatus());
            mchntOrderInfo.setBizStatus(BizStatusEnum.FAILED.getStatus());
            mchntOrderInfo.setTransStatus(TransStatusEnum.SYSTEM_REJECT.getStatus());
            orderService.updateOrderInfo(userOrderInfo, Arrays.asList(mchntOrderInfo), null);
            throw new BizException(RespCodeEnum.INSERT_TXN_EXPAND_ERROR.getRespCode(), RespCodeEnum.INSERT_TXN_EXPAND_ERROR.getRespDesc());
        }
        /*设置请求报文*/
        ComboPaymentRequest comboPaymentRequest = new ComboPaymentRequest();
        /*报文头赋值*/
        cc.rengu.igas.momp.facade.base.Header mompHeader = new cc.rengu.igas.momp.facade.base.Header();
        BeanUtil.beanCopy(header, mompHeader);
        mompHeader.setTraceNo(mompForClientPayOrderInfo.getChannelReconKey());
        mompHeader.setTxnNum("P01MO003");
        /*修改header里的源系统标识*/
        mompHeader.setSrcSysId(AppParamConstant.SYS_ID);
        comboPaymentRequest.setHeader(mompHeader);
        /*业务产品代码,组合营销产品代码*/
        comboPaymentRequest.setBizProdCode(comboBizProdCode);
        /*商户订单号*/
        comboPaymentRequest.setMchntOrderId(mompUserId);
        /*订单金额*/
        comboPaymentRequest.setTransAmt(userOrderInfo.getOrderAmt());
        /*获取 设置用户编号*/
        comboPaymentRequest.setUserId(userOrderInfo.getUserId());
        /*不上送手续费信息,不进行手续费优惠计算*/
        List<PaymentOrderDetailBean> orderDetailList = new ArrayList<>();
        PaymentOrderDetailBean paymentOrderDetailBean = new PaymentOrderDetailBean();
        paymentOrderDetailBean.setMchntNo(mchntOrderInfo.getMchntNo());
        paymentOrderDetailBean.setOrderAmt(mchntOrderInfo.getOrderAmt());
        paymentOrderDetailBean.setMchntSettleAmt(mchntOrderInfo.getOrderAmt());
        paymentOrderDetailBean.setFeeInputMode("0");
        orderDetailList.add(paymentOrderDetailBean);
        comboPaymentRequest.setOrderDetailList(orderDetailList);

        DubboService dubboService = new DubboServiceImpl();
        Result<ComboPaymentResponse> comboPaymentResponseResult = (Result) dubboService.callDubboService("paymentService", "comboPayment", comboPaymentRequest);
        if (null == comboPaymentResponseResult || !comboPaymentResponseResult.isSuccess() || null == comboPaymentResponseResult.getResult()) {
            /*营销失败，更新营销支付订单表状态失败*/
            rglog.error("调用营销失败，返回结果报文NULL");
            mompForClientPayOrderInfo.setTransStatus(TransStatusEnum.SYSTEM_REJECT.getStatus());
            mompForClientPayOrderInfo.setBizStatus(BizStatusEnum.FAILED.getStatus());
            mompForClientPayOrderInfo.setRespCode(RespCodeEnum.CALL_BIZ_SERVICE_ERROR.getRespCode());
            mompForClientPayOrderInfo.setRespDesc(RespCodeEnum.CALL_BIZ_SERVICE_ERROR.getRespDesc());
            orderService.updateOrderInfo(null, null, mompForClientPayOrderInfo);
        } else if (DubboMethodConstant.DUBBO_OVERTIME.equals(comboPaymentResponseResult.getResult().getRespCode()) || OltpRpcdEnum.BIZ_PROCESS_TIMEOUT.getRespCode().equals(comboPaymentResponseResult.getResult().getRespCode())) {
            /*相应超时，更新营销支付订单表并营销撤销*/
            rglog.error("调用营销超时{}", comboPaymentResponseResult.getResult().getRespDesc());
            /*用于营销冲正处理*/
            xmlTreeUtil.setXmlTreeObjectValue(BspsTreeNodeConstant.MOMP_COMPAY_ORDER_INFO, mompForClientPayOrderInfo);
            /*营销冲正*/
            cancelComboPayment(userOrderInfo.getSysSeqNum(), header);
            mompForClientPayOrderInfo.setTransStatus("3");
            mompForClientPayOrderInfo.setRespCode(comboPaymentResponseResult.getResult().getRespCode());
            mompForClientPayOrderInfo.setRespDesc(comboPaymentResponseResult.getResult().getRespDesc());
            orderService.updateOrderInfo(null, null, mompForClientPayOrderInfo);
        } else if (OltpRpcdEnum.TRANS_SUCCESS.getRespCode().equals(comboPaymentResponseResult.getResult().getRespCode())) {
            rglog.debug("调用成功,打印营销相应报文<{}>", JSON.toJSONString(comboPaymentResponseResult.getResult()));
            ComboPaymentResponse comboPaymentResponse = comboPaymentResponseResult.getResult();
            PaymentOrderDetailBean mompOrderDetail = comboPaymentResponse.getOrderDetailList().get(0);

            /*用户优惠营销金额*/
            String userDiscountAmt = comboPaymentResponse.getTotalSubsidy();
            /*对客营销金额,商户开展免充值营销活动时商户对客营销金额*/
            String customerMarketAmt = "0.00";

            /*商户清算本金:订单金额-对客营销金额(后续减去通道优惠金额)*/
            String realSettleAmt = mchntOrderInfo.getOrderAmt();
            /*营销通道优惠金额*/
            String mompChannelDiscountAmt = userDiscountAmt;
            //0-轧差清算（免充值）;1-正常清算（预充值）
            if ("0".equals(mompOrderDetail.getMoneyOffSettlementMethod())) {
                /*减去免充值的部分*/
                realSettleAmt = AmountUtil.subtraction(realSettleAmt, mompOrderDetail.getMoneyOffSubsidyMchnt());
                mompChannelDiscountAmt = AmountUtil.subtraction(mompChannelDiscountAmt, mompOrderDetail.getMoneyOffSubsidyTotal());
                customerMarketAmt = AmountUtil.addition(customerMarketAmt, mompOrderDetail.getMoneyOffSubsidyMchnt());

            }
            if ("0".equals(mompOrderDetail.getCouponMchntSettleMethod())) {
                /*减去免充值的部分*/
                realSettleAmt = AmountUtil.subtraction(realSettleAmt, mompOrderDetail.getCouponMchntSubsidy());
                mompChannelDiscountAmt = AmountUtil.subtraction(mompChannelDiscountAmt, mompOrderDetail.getCouponTotalSubsidy());
                customerMarketAmt = AmountUtil.addition(customerMarketAmt, mompOrderDetail.getCouponMchntSubsidy());
            }

            userOrderInfo.setRealPayAmt(AmountUtil.subtraction(userOrderInfo.getOrderAmt(), userDiscountAmt));//真正支付:待支付-通道侧优惠,此时未调通道,登记待支付
            userOrderInfo.setRealDiscountAmt(AmountUtil.addition(userOrderInfo.getRealDiscountAmt(), userDiscountAmt));//用户优惠：营销模块对客+通道优惠

            mchntOrderInfo.setCustomerMarketAmt(customerMarketAmt);//对客营销,商户开展免充值营销活动时商户对客营销金额
            mchntOrderInfo.setRedeemCouponIds(mompOrderDetail.getCouponNo());//卡券编号
            mchntOrderInfo.setRealSettleAmt(realSettleAmt);//实际清算本金

            mompForClientPayOrderInfo.setChannelDiscountAmt(mompChannelDiscountAmt);//营销通道优惠金额

            /*更新订单*/
            userOrderInfo.setUpdateTime(DateUtil.getCurrentDateTime(BspsAppParamConstant.yyyy_MM_dd_HHmmssSSS));
            mchntOrderInfo.setUpdateTime(DateUtil.getCurrentDateTime(BspsAppParamConstant.yyyy_MM_dd_HHmmssSSS));
            mompForClientPayOrderInfo.setUpdateTime(DateUtil.getCurrentDateTime(BspsAppParamConstant.yyyy_MM_dd_HHmmssSSS));
            /*营销订单状态状态设置*/
            mompForClientPayOrderInfo.setTransStatus(TransStatusEnum.TRANS_SUCC.getStatus());
            mompForClientPayOrderInfo.setBizStatus(BizStatusEnum.FINISH.getStatus());
            mompForClientPayOrderInfo.setRespCode(comboPaymentResponse.getRespCode());
            mompForClientPayOrderInfo.setRespDesc(comboPaymentResponse.getRespDesc());
            /*打印用户订单和商户订单*/
            rglog.debug(JSON.toJSONString(userOrderInfo));
            rglog.debug(JSON.toJSONString(mchntOrderInfo));
            /*更新内部树用户订单表信息和商户订单表信息*/
            xmlTreeUtil.setXmlTreeObjectValue(BspsTreeNodeConstant.USER_ORDER_INFO, userOrderInfo);
            xmlTreeUtil.setXmlTreeObjectValue(BspsTreeNodeConstant.MCHNT_ORDER_INFO, mchntOrderInfo);
            List<MchntOrderInfo> mchntOrderInfoList = new ArrayList<>();
            mchntOrderInfoList.add(mchntOrderInfo);
            if (!orderService.updateOrderInfo(userOrderInfo, mchntOrderInfoList, mompForClientPayOrderInfo)) {
                rglog.error("更新用户、商户、营销支付订单信息失败,instId:<{}>,sysSeqNum:<{}>,mchntOrderId:<{}>",
                        userOrderInfo.getInstId(), userOrderInfo.getSysSeqNum(), userOrderInfo.getMchntOrderId());
                throw new BizException(RespCodeEnum.UPDATE_ORDER_STATUS_ERROR.getRespCode(), RespCodeEnum.UPDATE_ORDER_STATUS_ERROR.getRespDesc());
            }
            rglog.debug("----------调用对客营销成功----------");
            /*用于营销冲正处理*/
            xmlTreeUtil.setXmlTreeObjectValue(BspsTreeNodeConstant.MOMP_COMPAY_ORDER_INFO, mompForClientPayOrderInfo);
            return;
        } else {
            /*营销失败，更新营销支付订单表状态失败*/
            rglog.error("调用营销失败{}", comboPaymentResponseResult.getResult().getRespDesc());
            mompForClientPayOrderInfo.setTransStatus(TransStatusEnum.SYSTEM_REJECT.getStatus());
            mompForClientPayOrderInfo.setBizStatus(BizStatusEnum.FAILED.getStatus());
            mompForClientPayOrderInfo.setRespCode(comboPaymentResponseResult.getResult().getRespCode());
            mompForClientPayOrderInfo.setRespDesc(comboPaymentResponseResult.getResult().getRespDesc());
            orderService.updateOrderInfo(null, null, mompForClientPayOrderInfo);
        }

        rglog.error("计算手续费优惠异常,不参与优惠,正常登记商户手续费,实收手续费,商户结算净额等字段.");
        //通过日终对账方式,对出不平,通过手工调账调整商户手续费营销.
        mchntOrderInfo.setMchntDiscountFee("0.00");
        mchntOrderInfo.setRealMchntFee(mchntOrderInfo.getMchntFee());
        mchntOrderInfo.setUpdateTime(DateUtil.getCurrentDateTime("yyyy-MM-dd HH:mm:ss.SSS"));
        /*d0实时入账手续费四舍五入处理,手续费计算,营销手续费优惠计算,均已保留两位小数*/
        // if (AppParamConstant.YES.equals(mchntOrderInfo.getRealSettleFlag())) {
        //     mchntOrderInfo.setRealMchntFee(AmountUtil.rounding(mchntOrderInfo.getRealMchntFee(), 2));
        //     mchntOrderInfo.setMchntFee(AmountUtil.rounding(mchntOrderInfo.getMchntFee(), 2));
        // }
        mchntOrderInfo.setMchntSettleAmt(AmountUtil.subtraction(mchntOrderInfo.getRealSettleAmt(), mchntOrderInfo.getRealMchntFee()));
    }

    //    @Override
//    public void comboRefund(MchntOrderInfo mchntOrderInfo, MchntOrderInfo orimchntOrderInfo, Header header) throws Exception {
//        /*修改header里的源系统标识*/
//        header.setSrcSysId(AppParamConstant.SYS_ID);
//        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
//        /*查询支付交易中对应的营销支付订单表*/
//        /* 定义订单操作接口*/
//        PayOrderInfoMapper payOrderInfoMapper = new PayOrderInfoMapperImpl();
//        List<PayOrderInfo> payOrderInfoList = payOrderInfoMapper.selectPayOrderInfoBySysSeqNum(orimchntOrderInfo.getInstId(), orimchntOrderInfo.getSysSeqNum());
//        if (null == payOrderInfoList) {
//            rglog.info("无营销支付交易，无需营销退货");
//            return;
//        }
//        List<PayOrderInfo> orderInfos = payOrderInfoList.stream().filter(item -> item.getMsgDstId().equals(ChannelEnum.MOMP.getChannelType()) && "0".equals(item.getDstCallIndex())
//                && (item.getTransStatus().equals(TransStatusEnum.TRANS_SUCC.getStatus()))).collect(Collectors.toList());
//        /*定义营销支付订单对象*/
//        if (orderInfos.isEmpty()) {
//            rglog.info("原营销支付交易失败，无需营销退货");
//            return;
//        }
//        rglog.info("<<<<<<营销退货开始>>>>>>>");
//        /*获取原营销的支付订单表*/
//        PayOrderInfo payComboOrderInfo = orderInfos.get(0);
//        /*塞入内部树异步线程处理*/
//        xmlTreeUtil.setXmlTreeObjectValue(McpsTreeNodeConstant.MOMP_COMPAY_ORDER_INFO, payComboOrderInfo);
//        /*定义订单操作接口*/
//        /*定义营销支付订单对象*/
//        PayOrderInfo comboRefundOrderInfo = new PayOrderInfo();
//        BeanUtil.beanCopy(payComboOrderInfo, comboRefundOrderInfo);
//        /*部分退款 营销订单记的订单金额 应是退款金额 */
//        comboRefundOrderInfo.setOrderAmt(mchntOrderInfo.getOrderAmt());
//        comboRefundOrderInfo.setRealPayAmt(comboRefundOrderInfo.getOrderAmt());
//        comboRefundOrderInfo.setTxnDate(DateUtil.getCurrentDate());
//        comboRefundOrderInfo.setTxnTime(DateUtil.getCurrentTime());
//        comboRefundOrderInfo.setSysSeqNum(header.getTraceNo());
//        comboRefundOrderInfo.setMsgDstId(ChannelEnum.MOMP.getChannelType());
//        comboRefundOrderInfo.setTxnNum(header.getTxnNum());
//        comboRefundOrderInfo.setMchntOrderId(mchntOrderInfo.getMchntOrderId());
//        /*设置调用序号*/
//        String strIndex = xmlTreeUtil.getXmlTreeStringValue("currentDstCallIndex");
//        Integer mompCallIndex = new Integer((StringUtil.isEmptyOrNull(strIndex)) ? "0" : strIndex);
//        comboRefundOrderInfo.setDstCallIndex(mompCallIndex.toString());
//        String dstMompCallIndex = Integer.toString(mompCallIndex + 1);
//        /*存储当前调用序号*/
//        xmlTreeUtil.setXmlTreeStringValue("currentDstCallIndex", dstMompCallIndex);
//        /*对账唯一主键*/
//        comboRefundOrderInfo.setChannelReconKey(header.getTraceNo() + mompCallIndex.toString());
//        comboRefundOrderInfo.setChannelSeqNum(comboRefundOrderInfo.getChannelReconKey());
//        /*创建时间和更新时间*/
//        comboRefundOrderInfo.setCreateTime(DateUtil.getCurrentDateTime("yyyy-MM-dd HH:mm:ss.SSS"));
//        comboRefundOrderInfo.setUpdateTime(DateUtil.getCurrentDateTime("yyyy-MM-dd HH:mm:ss.SSS"));
//        /*保存原营销的系统流水号*/
//        comboRefundOrderInfo.setOrigTxnDate(payComboOrderInfo.getTxnDate());
//        comboRefundOrderInfo.setOrigSysSeqNum(payComboOrderInfo.getSysSeqNum());
//        /*获取通道交易码*/
//        comboRefundOrderInfo.setDstTxnNum(McpsTxnNumConstant.MOMP_COMBO_PAYMENT_REFUND);
//        /*设置支付订单状态,交易状态，0：初始状态，业务状态：00处理中*/
//        comboRefundOrderInfo.setTransStatus(TransStatusEnum.TRANS_INIT.getStatus());
//        comboRefundOrderInfo.setBizStatus(BizStatusEnum.PROCESSING.getStatus());
//        comboRefundOrderInfo.setRespDesc(null);
//        comboRefundOrderInfo.setRespCode(null);
//        OrderService orderService = new OrderServiceImpl();
//        /*记录营销支付订单*/
//        if (!orderService.registerOrderInfo(null, null, comboRefundOrderInfo)) {
//            rglog.error("登记营销退款订单信息失败,instId:<{}>,sysSeqNum:<{}>,mchntOrderId:<{}>,msgDstId:<{}>",
//                    comboRefundOrderInfo.getInstId(), comboRefundOrderInfo.getSysSeqNum(), comboRefundOrderInfo.getMchntOrderId(), comboRefundOrderInfo.getMsgDstId());
//            return;
//        }
//        /*保存节点于内部树*/
//        xmlTreeUtil.setXmlTreeObjectValue(McpsTreeNodeConstant.MOMP_REFUND_ORDER_INFO, comboRefundOrderInfo);
//        /*设置请求报文*/
//        /*设置请求报文*/
//        ComboPaymentRefundRequest comboPaymentReturnRequest = new ComboPaymentRefundRequest();
//        /*报文头赋值*/
//        cc.rengu.igas.momp.facade.base.Header mompHeader = new cc.rengu.igas.momp.facade.base.Header();
//        BeanUtil.beanCopy(header, mompHeader);
//        mompHeader.setTxnNum(McpsTxnNumConstant.MOMP_COMBO_PAYMENT_REFUND);
//        mompHeader.setTraceNo(header.getTraceNo() + mompCallIndex.toString());
//        mompHeader.setVersion("1.0.0");
//        comboPaymentReturnRequest.setHeader(mompHeader);
//        /*商户订单号*/
//        comboPaymentReturnRequest.setMchntOrderId(mchntOrderInfo.getMchntOrderId());
//        /*原交易流水号*/
//        comboPaymentReturnRequest.setOrigTraceNo(payComboOrderInfo.getChannelReconKey());
//        /*原交易日期*/
//        comboPaymentReturnRequest.setOrigTxnDate(orimchntOrderInfo.getTxnDate());
//        /*订单金额*/
//        comboPaymentReturnRequest.setTransAmt(orimchntOrderInfo.getOrderAmt());
//        /*本次退款金额*/
//        comboPaymentReturnRequest.setReturnAmt(comboRefundOrderInfo.getOrderAmt());
//        /*设置userID*/
//        /*根据流水号获取用户订单表*/
//        UserOrderInfoMapper userOrderInfoMapper = new UserOrderInfoMapperImpl();
//        UserOrderInfo userOrderInfo = userOrderInfoMapper.selectUserOrderInfoByPrimaryKey(header.getInstId(), mchntOrderInfo.getSysSeqNum());
//        comboPaymentReturnRequest.setUserId(userOrderInfo.getUserId());
//        PaymentReturnOrderInfoBean paymentReturnOrderInfoBean = new PaymentReturnOrderInfoBean();
//        /*商户号*/
//        paymentReturnOrderInfoBean.setMchntNo(mchntOrderInfo.getMchntNo());
//        /** 退货订单金额 */
//        paymentReturnOrderInfoBean.setOrderAmt(mchntOrderInfo.getOrderAmt());
//        /*退货商户应收手续费金额*/
//        paymentReturnOrderInfoBean.setMchntFeeReceivable(mchntOrderInfo.getMchntFee());
//        /*退货跟新标识*/
//        /*手续费收取方式*/
//        List<PaymentReturnOrderInfoBean> paymentReturnOrderInfoBeanList = new ArrayList<PaymentReturnOrderInfoBean>();
//        paymentReturnOrderInfoBeanList.add(paymentReturnOrderInfoBean);
//        comboPaymentReturnRequest.setReturnOrderDetailList(paymentReturnOrderInfoBeanList);
//        DubboService dubboService = new DubboServiceImpl();
//        /*异步调起营销退货*/
//        dubboService.asynCallDubboService(McpsServiceNameConstant.MOMP_SERVICE, McpsServiceNameConstant.MOMP_REFUND_METHOD, comboPaymentReturnRequest, "McpsAsynComboPaymentRefundService");
//        rglog.debug("--------营销退货结束-------");
//    }

    @Override
    public void cancelComboPayment(String oriSysSeqNum, Header header) throws Exception {
        /*修改header里的源系统标识*/
        header.setSrcSysId(AppParamConstant.SYS_ID);
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();

        PayOrderInfo payComboOrderInfo = (PayOrderInfo) xmlTreeUtil.getXmlTreeObjectValue(BspsTreeNodeConstant.MOMP_COMPAY_ORDER_INFO, PayOrderInfo.class);
        if (null == payComboOrderInfo) {
            /*查询支付交易中对应的营销支付订单表*/
            PayOrderInfoMapper payOrderInfoMapper = new PayOrderInfoMapperImpl();
            List<PayOrderInfo> payOrderInfoList = payOrderInfoMapper.selectPayOrderInfoBySysSeqNum(header.getInstId(), oriSysSeqNum);
            if (null == payOrderInfoList) {
                rglog.debug("无营支付交易，无需营销撤销");
                return;
            }

            List<PayOrderInfo> orderInfos = payOrderInfoList.stream().filter(item -> item.getMsgDstId().equals(ChannelEnum.MOMP.getChannelType()) && "0".equals(item.getDstCallIndex())
                    && ((item.getTransStatus().equals(TransStatusEnum.TRANS_SUCC.getStatus()) && item.getBizStatus().equals(BizStatusEnum.FINISH.getStatus())) || (item.getTransStatus().equals(TransStatusEnum.TRANS_TIMEOUT.getStatus()) && item.getBizStatus().equals(BizStatusEnum.PROCESSING.getStatus())))).collect(Collectors.toList());
            /*定义营销支付订单对象*/
            if (orderInfos.isEmpty()) {
                rglog.debug("原营销交易状态异常，无需营销撤销");
                return;
            }
            /*获取原营销的支付订单表*/
            payComboOrderInfo = orderInfos.get(0);
        }

        rglog.debug("--------营销撤销开始-------");
        /*塞入内部树异步线程处理*/
        xmlTreeUtil.setXmlTreeObjectValue(BspsTreeNodeConstant.MOMP_COMPAY_ORDER_INFO, payComboOrderInfo);
        PayOrderInfo comboCancelPayOrderInfo = new PayOrderInfo();
        BeanUtil.beanCopy(payComboOrderInfo, comboCancelPayOrderInfo);
        comboCancelPayOrderInfo.setTxnDate(DateUtil.getCurrentDate());
        comboCancelPayOrderInfo.setTxnTime(DateUtil.getCurrentTime());
        comboCancelPayOrderInfo.setSysSeqNum(xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.SYS_SEQ_NUM));
        comboCancelPayOrderInfo.setTxnNum(header.getTxnNum());
        comboCancelPayOrderInfo.setMsgDstId(ChannelEnum.MOMP.getChannelType());
        comboCancelPayOrderInfo.setDstCallIndex("1");
        /*对账唯一主键*/
        comboCancelPayOrderInfo.setChannelReconKey(xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.SYS_SEQ_NUM) + comboCancelPayOrderInfo.getDstCallIndex());
        /*设置通道流水号*/
        comboCancelPayOrderInfo.setChannelSeqNum(comboCancelPayOrderInfo.getChannelReconKey());
        /*设置对应的原交易日期和流水号*/
        comboCancelPayOrderInfo.setOrigSysSeqNum(payComboOrderInfo.getSysSeqNum());
        comboCancelPayOrderInfo.setOrigTxnDate(payComboOrderInfo.getTxnDate());
        /*设置营销冲正状态*/
        comboCancelPayOrderInfo.setTransStatus(TransStatusEnum.TRANS_INIT.getStatus());
        comboCancelPayOrderInfo.setBizStatus(BizStatusEnum.PROCESSING.getStatus());
        comboCancelPayOrderInfo.setCreateTime(DateUtil.getCurrentDateTime("yyyy-MM-dd HH:mm:ss.SSS"));
        comboCancelPayOrderInfo.setUpdateTime(DateUtil.getCurrentDateTime("yyyy-MM-dd HH:mm:ss.SSS"));
        /*设置通道交易码*/
        comboCancelPayOrderInfo.setDstTxnNum("P02MO001");
        comboCancelPayOrderInfo.setPayType("*");
        /*设置订单状态*/
        comboCancelPayOrderInfo.setRespCode(null);
        comboCancelPayOrderInfo.setRespDesc(null);
        rglog.info("打印营销撤销支付订单表<{}>", JSON.toJSONString(comboCancelPayOrderInfo));
        OrderService orderService = new OrderServiceImpl();
        if (!orderService.registerOrderInfo(null, null, comboCancelPayOrderInfo)) {
            rglog.error("登记营销撤销订单信息失败,instId:<{}>,sysSeqNum:<{}>,mchntOrderId:<{}>,msgDstId:<{}>",
                    comboCancelPayOrderInfo.getInstId(), comboCancelPayOrderInfo.getSysSeqNum(), comboCancelPayOrderInfo.getMchntOrderId(), comboCancelPayOrderInfo.getMsgDstId());
            return;
        }
        /*保存节点于内部树*/
        xmlTreeUtil.setXmlTreeObjectValue(BspsTreeNodeConstant.MOMP_CANCEL_ORDER_INFO, comboCancelPayOrderInfo);
        /*设置头报文*/
        ComboPaymentReversalRequest comboPaymentRevsalRequest = new ComboPaymentReversalRequest();
        cc.rengu.igas.momp.facade.base.Header mompHeader = new cc.rengu.igas.momp.facade.base.Header();
        BeanUtil.beanCopy(header, mompHeader);
        mompHeader.setTxnNum("P02MO001");
        mompHeader.setTraceNo(xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.SYS_SEQ_NUM) + comboCancelPayOrderInfo.getDstCallIndex());
        mompHeader.setVersion("1.0.0");
        comboPaymentRevsalRequest.setHeader(mompHeader);
        comboPaymentRevsalRequest.setOrigTraceNo(payComboOrderInfo.getChannelReconKey());
        DubboService dubboService = new DubboServiceImpl();
        dubboService.asynCallDubboService("paymentService", "comboPaymentReversal", comboPaymentRevsalRequest, "BspsAsynComboPaymentCancelService");
        rglog.info("--------营销撤销结束-------");
    }

    /**
     * 拼接营销产品代码
     *
     * @param txnNum  交易码
     * @param bizType 业务细分
     * @return 营销产品代码
     */
    private String getComboBizProdCode(String txnNum, String bizType) {
        String comboBizProdCode = null;
        if ("P01BS002".equals(txnNum)) {
            comboBizProdCode = "MC021" + bizType + "0";
        }
        return comboBizProdCode;
    }

}
